﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace Solidi
{
	public static class DependencyDecoratorExtensions
	{
		public static IDependencyDecorator As(this IDependencyDecorator source, Type type)
		{
			source.Decorate(dependency => new DependencyRegistration(dependency, new DependencyKey(dependency.Key, type)));

			return source;
		}

		public static IDependencyDecorator As<TType>(this IDependencyDecorator source)
		{
			return As(source, typeof(TType));
		}

		public static IDependencyDecorator Lifestyle(this IDependencyDecorator source, IDependencyLifestyle lifestyle)
		{
			source.Decorate(dependency => new DependencyRegistration(dependency, lifestyle));

			return source;
		}

		public static IDependencyDecorator Singleton(this IDependencyDecorator source)
		{
			return Lifestyle(source, new SingletonLifestyle());
		}

		public static IDependencyDecorator PerGraph(this IDependencyDecorator source)
		{
			return Lifestyle(source, new PerGraphLifestyle());
		}

		public static IDependencyDecorator Transient(this IDependencyDecorator source)
		{
			return Lifestyle(source, new TransientLifestyle());
		}

		public static IDependencyDecorator Pooled(this IDependencyDecorator source, int poolSize)
		{
			return Pooled(source, poolSize, Timeout.InfiniteTimeSpan);
		}

		public static IDependencyDecorator Pooled(this IDependencyDecorator source, int poolSize, TimeSpan timeout)
		{
			return Lifestyle(source, new PooledLifestyle(poolSize, timeout));
		}

		public static IDependencyDecorator Named(this IDependencyDecorator source, string name)
		{
			source.Decorate(dependency => new DependencyRegistration(dependency, new DependencyKey(dependency.Key, name)));

			return source;
		} 
	}
}
